package com.hp.tiger.concurrent.classloader.chapter4;

/**
 * @author XavierDong
 **/

/**
 *
 * 异或 加解密，异或2遍，就直接变回原文了
 *
 *
 */
public class SimpleEncrypt {

    private static final String plain = "Hello Classloader";

    private static final byte ENCRYPT_FACTOR = (byte) 0xff;

    public static void main(String[] args) {
        byte[] bytes = plain.getBytes();

        byte[] encrypt = new byte[bytes.length];

        for (int i = 0; i < bytes.length; i++) {
            encrypt[i] = (byte) (bytes[i] ^ ENCRYPT_FACTOR);
        }
        System.out.println(new String(encrypt));

        byte[] decrypt = new byte[encrypt.length];
        for (int i = 0; i < encrypt.length; i++) {
            decrypt[i] = (byte) (encrypt[i] ^ ENCRYPT_FACTOR);
        }
        System.out.println(new String(decrypt));
    }
}
